package com.chenxiao.httputils.utils;

import org.springframework.http.*;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

/**
 * @Author: CX
 * @Date: Created in  2023/12/14 10:49
 * @version: v1.0
 * @Description: TODO
 **/
@Component
public class MyRestTemplateClient {

    private final RestTemplate restTemplate = new RestTemplate();

    /* public MyRestTemplateClient(RestTemplate restTemplate) {
         this.restTemplate = restTemplate;
     }*/
    public String sendPostRequest(String url, String jsonParams, String headerParams) {
        HttpHeaders headers = new HttpHeaders();
        headers.add("User-Agent", headerParams); // 你可以根据需要添加其他头信息

        HttpEntity<String> request = new HttpEntity<>(jsonParams, headers);

        ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, request, String.class);

        return response.getBody();
    }
    public String setGetRequest(String url){
        RestTemplate restTemplate = new RestTemplate();
        return restTemplate.getForObject(url, String.class);
    }
    public String sendPost(String url, String jsonObject){
       return "";
    }

}
